#include "gethistoryrequest.h"
#include "response/gethistoryresponse.h"
#include "network/networkmanager.h"


#include <QUrl>
#include <QDebug>


GetHistoryRequest::GetHistoryRequest(qint64 partnerId,
                                     int messageCount,
                                     qint64 lastId):
    m_response(new GetHistoryResponse(this)),
    m_partnerId(partnerId),
    m_messageCount(messageCount),
    m_lastId(lastId)
{
}


GetHistoryRequest::~GetHistoryRequest()
{
    delete m_response;
    m_response = 0;
}


QUrl GetHistoryRequest::url() const
{
    Network::Manager *netWorkManager = Network::Manager::instance();
    QString session_key = netWorkManager->sessionKey();
    QString url = QString("http://mapi2.me.zing.vn/frs/mapi2/messchat?method=mess.gethistoryprivate&session_key=%1&page=1&records=%2&fid=%3")
            .arg(session_key).arg(m_messageCount).arg(m_partnerId);

    return QUrl(url);
}


const Network::JSONListResponse &GetHistoryRequest::jsonListResponse() const
{
    return *m_response;
}


Network::JSONListResponse &GetHistoryRequest::jsonListResponse()
{
    return *m_response;
}
